// import { useUserStore } from '@/stores/modules/user';

// const { SET_ROUTECACHE, routeCache } = useUserStore();

// 更新路由切换缓存tab
export function updateRouteTab(useUserStore: any, route: any) {
    const { SET_ROUTECACHE, routeCache } = useUserStore();
    const routeObj = {
        path: route.path,
        name: route.name,
        params: route.params,
        query: route.query
    }
    if(!routeCache){
        SET_ROUTECACHE([routeObj])
        return;
    }
    const newArr = JSON.parse(JSON.stringify(routeCache));
    const index = newArr.findIndex((item: any) => item.path === route.path);
    if( index >= 0 ){
        newArr[index] = routeObj;
    }else{
        newArr.push(routeObj);
    }
    SET_ROUTECACHE(newArr);
}

// 删除路由
export function deleteRoute(useUserStore: any, path: string) {
    const { SET_ROUTECACHE, routeCache } = useUserStore();
    const newArr: any[] = JSON.parse(JSON.stringify(routeCache));
    const index = newArr.findIndex((item: any) => item.path === path);
    console.log(index);
    
    if( index >= 0){
        newArr.splice(index, 1);
        SET_ROUTECACHE(newArr);
        return true;
    }
    return false
}